const utils = require('../../utils/util.js')
const gd = getApp().globalData;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    current: 'contact',
    contents: [],
    area:{},
    isShowMap: true,   //展示地图
  },
  onLoad:function(){
    wx.showLoading({
      title: '加载中',
      mask:true
    })
    const area = wx.getStorageSync('area')
    let { museum_name, longitude, latitude} = area
    //设置标题栏文本
    wx.setNavigationBarTitle({
      title: area.museum_name,
    })
    this.setData({
      area,
      markers: [{
        id: 1,
        iconPath: "/images/location.png",
        label: {
          content: "点击红色图标导航",
          color: "#b76524",
          textAlign: "left",
          fontSize:12,
        },
        latitude,
        longitude
      }],
    })
    const contactjson = wx.getStorageSync('contactjson')//请求存储的联系信息json
    //如果不存在重新请求数据
    if (contactjson) {
      this.setData({
        contents: contactjson
      })
    } else {
      utils.requestExcelToJson(gd.domain + gd.respre + area.museum + '/' + 'contact.xls')
        .then(res => {
          this.setData({
            contents: res
          })
          wx.setStorageSync('contactjson', res)
        })
    }
  },
  onReady:function(){
    wx.hideLoading()
  },
  //底部导航栏
  handleChange_nav({ detail }) {
    if (detail.key == 'index') {
      wx.reLaunch({
        url: `/pages/${detail.key}/${detail.key}`,
      })
    }
  },
  /**
   * 重置数据
   */
  resetData: function (e) {
    wx.clearStorage()
    wx.reLaunch({
      url: '/pages/area/area',
    })
  },


  //marker点击事件
  markertap: function(){
    let { longitude, latitude, museum_name } = this.data.area
    wx.openLocation({
      latitude: latitude,
      longitude: longitude,
      name: museum_name,
      scale: 28
    })
  }
})
